package approve.action;

import java.util.List;

import model.pojo.Employee;
import resource.pojo.Approvedoc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import approval.dao.ApproveDocumentDAO;

public class My_App_DeclineDocument extends Activity {
	String database = "admin";
	Bundle language = null;

	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
			lang = extras.getString("lang");
			language = extras.getBundle(lang);
		}
		return database;
	}

	// public String getLang() {
	// Bundle extras = getIntent().getExtras();
	// if (extras != null) {
	// lang = extras.getString("lang");
	// }
	// return lang;
	// }

	String lang = "EN";
	Approvedoc AppDoc = null;
	Employee emp = null;
	ListView list;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_app_declinedocument);
		getDatabase();

		emp = (Employee) getIntent().getExtras().get("em");
		List<Approvedoc> listDocs = getListAppovedDocument();
		if (language != null) {
			TextView la_headerTitle = (TextView) findViewById(R.id.la_headerTitle);
			la_headerTitle.setText(language.getString("declined-document") + " ("
					+ listDocs.size() + "):");
		}
		if (listDocs.size() > 0) {
			list = (ListView) findViewById(R.id.lst_mydeclinedocument);
			list.setAdapter(new ArrayAdapter<Approvedoc>(this,
					android.R.layout.simple_list_item_1, listDocs));
			list.setOnItemClickListener(viewForm);
		} else {
			TextView empltyList = (TextView) findViewById(R.id.empltyList);
			if (language != null) {
				empltyList.setText(language.getString("no_data"));
			}
		}
	}

	private OnItemClickListener viewForm = new OnItemClickListener() {
		public void onItemClick(android.widget.AdapterView<?> lstAppDoc,
				android.view.View arg1, int arg2, long arg3) {
			Approvedoc AppDoc = (Approvedoc) lstAppDoc.getItemAtPosition(arg2);
			System.out.println("tyepdoc: " + AppDoc.getiDTypeDoc());
			if (AppDoc.getiDTypeDoc() == 14) {
				Intent intent = new Intent(My_App_DeclineDocument.this,
						My_ViewForm14.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				intent.putExtra("delete", "delete");
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() == 15) {
				Intent intent = new Intent(My_App_DeclineDocument.this,
						My_ViewForm15.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				intent.putExtra("delete", "delete");
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() < 11) {
				Intent intent = new Intent(My_App_DeclineDocument.this,
						My_ViewForm_Lessthan10.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				intent.putExtra("delete", "delete");
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() == 11) {
				Intent intent = new Intent(My_App_DeclineDocument.this,
						My_ViewForm11.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				intent.putExtra("delete", "delete");
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() == 12) {
				Intent intent = new Intent(My_App_DeclineDocument.this,
						My_ViewForm12.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				intent.putExtra("delete", "delete");
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() == 13) {
				Intent intent = new Intent(My_App_DeclineDocument.this,
						My_ViewForm13.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				intent.putExtra("delete", "delete");
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() == 16) {
				Intent intent = new Intent(My_App_DeclineDocument.this,
						My_viewform16.class);
				intent.putExtra("AppDocID", AppDoc.getiDApproveDoc());
				intent.putExtras(getIntent().getExtras());
				intent.putExtra("delete", "delete");
				startActivity(intent);
			}

		};
	};

	public List<Approvedoc> getListAppovedDocument() {
		System.out.println("aaaaa");
		// System.out.println("lst1"+ApproveDocumentDAO.getAllDoc(1,"","",emp.getIdemployee(),
		// getDatabase()));
		return ApproveDocumentDAO.getAllDoc(3, "", "", emp.getIdemployee(),
				getDatabase());
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
	        // do something on back.
			Intent intent=new Intent(My_App_DeclineDocument.this,MainFrame.class);
			intent.putExtras(getIntent().getExtras());
			startActivityForResult(intent, 0);
			
	        return true;
	    }

		return super.onKeyDown(keyCode, event);
	}
}
